package com.simdo.g768.Adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.simdo.g768.Bean.ArfcnPciBean;
import com.simdo.g768.Listener.CellClickListener;
import com.simdo.g768.R;

import java.util.List;

public class CfgAdapter extends RecyclerView.Adapter<CfgAdapter.ViewHolder> {
	private final List<ArfcnPciBean> list;
	private final CellClickListener listener;
	private final CellCfgAdapter adapter;
	private final int index;

	public CfgAdapter(CellCfgAdapter adapter, List<ArfcnPciBean> list, CellClickListener listener, int pos) {
		this.adapter = adapter;
		this.list = list;
		this.listener = listener;
		this.index = pos;
	}

	@NonNull
	@Override
	public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
		View view = LayoutInflater.from(viewGroup.getContext())
				.inflate(R.layout.item_arfcn_pci, viewGroup, false);

		return new ViewHolder(view);
	}

	@Override
	public void onBindViewHolder(@NonNull ViewHolder viewHolder, int position) {
		final int pos = position;
		ArfcnPciBean bean = list.get(pos);
		viewHolder.arfcn.setText(String.valueOf(bean.getArfcn()));
		viewHolder.pci.setText(String.valueOf(bean.getPci()));
		viewHolder.pci.setVisibility(adapter.isAutoPci ? View.GONE : View.VISIBLE);
		viewHolder.ll_cfg.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				listener.onClick(index, 2 + pos);
			}
		});
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public int getItemCount() {
		return list.size();
	}

	public static class ViewHolder extends RecyclerView.ViewHolder {
		LinearLayout ll_cfg;
		TextView arfcn, pci;
		public ViewHolder(View view) {
			super(view);
			ll_cfg = view.findViewById(R.id.ll_cfg);
			arfcn = view.findViewById(R.id.arfcn);
			pci = view.findViewById(R.id.pci);
		}
	}
}
